
#ifndef __SYSLIST_H
#define __SYSLIST_H


#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */

	
#include "System.h"
	
/**
 * @ingroup los_list
 * Structure of a node in a doubly linked list.
 */
typedef struct tagList 
{
    struct tagList *pstPrev; /**< Current node's pointer to the previous node */
    struct tagList *pstNext; /**< Current node's pointer to the next node */
} SysList_T;


inline  void List_Init(SysList_T *_list)
{
    _list->pstNext = _list;
    _list->pstPrev = _list;
}

#define LIST_FIRST(object) ((object)->pstNext)


inline void List_Add(SysList_T *_list, SysList_T *_node)
{
    _node->pstNext = _list->pstNext;
    _node->pstPrev = _list;
    _list->pstNext->pstPrev = _node;
    _list->pstNext = _node;
}


inline void List_TailInsert(SysList_T *_list, SysList_T *_node)
{
    List_Add(_list->pstPrev, _node);
}

inline void List_HeadInsert(SysList_T *_list, SysList_T *_node)
{
    List_Add(_list, _node);
}

inline void List_Delete(SysList_T *_node)
{
    _node->pstNext->pstPrev = _node->pstPrev;
    _node->pstPrev->pstNext = _node->pstNext;
    _node->pstNext = (SysList_T *)NULL;
    _node->pstPrev = (SysList_T *)NULL;
}

inline BOOL List_Empty(SysList_T *_node)
{
    return (BOOL)(_node->pstNext == _node);
}


#define LIST_OFF_SET_OF(type, member) ((uint32_t)&(((type *)0)->member)) /*lint -e(413) */


#define LIST_ENTRY(item, type, member) \
    ((type *)(void *)((char *)(item) - LIST_OFF_SET_OF(type, member))) \


#define LIST_FOR_EACH_ENTRY(item, list, type, member) \
    for ((item) = LIST_ENTRY((list)->pstNext, type, member); \
            &(item)->member != (list); \
            (item) = LIST_ENTRY((item)->member.pstNext, type, member))


#define LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
    for ((item) = LIST_ENTRY((list)->pstNext, type, member), \
            (next) = LIST_ENTRY((item)->member.pstNext, type, member); \
            &((item)->member) != (list); \
            (item) = (next), (next) = LIST_ENTRY((item)->member.pstNext, type, member))


inline void List_DelInit(SysList_T *_list)
{
    _list->pstNext->pstPrev = _list->pstPrev;
    _list->pstPrev->pstNext = _list->pstNext;
    List_Init(_list);
}

#define LIST_FOR_EACH(item, list) \
    for ((item) = (list)->pstNext; (item) != (list); (item) = (item)->pstNext)

#define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \
    for ((item) = (list)->pstNext, (next) = (item)->pstNext; (item) != (list); \
            (item) = (next), (next) = (item)->pstNext)


#define LOS_DL_LIST_HEAD(list) \
    SysList_T list = { &(list), &(list) }

	
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif /* _LOS_LIST_H */
